//
//  VipViewController.m
//  家范
//
//  Created by 吴军虎吴军虎 on 16/4/20.
//  Copyright © 2016年 lanjue. All rights reserved.
//

#import "VipViewController.h"
#import "SJAvatarBrowser.h"

//5s的大小
#define HEIGHT [[UIScreen mainScreen] bounds].size.height / 568
#define WEIGHT [[UIScreen mainScreen] bounds].size.width / 320

@interface VipViewController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate>

@property (nonatomic,retain) UIView *myheaderView;
@property (nonatomic,retain) UIView *bigWightView;
@property (nonatomic,retain) UIImageView *imageView;
@property (nonatomic,retain) UIImageView *renimage;
@property (nonatomic,retain) UIButton *jiaobtn;
@property (nonatomic,retain) UIView *tsView;
@property(nonatomic,assign)BOOL isSelrct;
@property (nonatomic,retain) UIImageView  *headImage;
@property (nonatomic,retain) UIView *backView;
@end

@implementation VipViewController

-(void) viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden=NO;
}

- (void)viewWillDisappear:(BOOL)animated {
    
    self.navigationController.navigationBarHidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor=LV;
    
    self.title=@"认证身份";
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(Back:)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    
    //内容
    [self createRong];
    
    //上传图片
    [self createShang];
}


#pragma  mark 内容
-(void)   createRong
{
    //白色框
    _bigWightView=[[UIView alloc]init];
    _bigWightView.backgroundColor=[UIColor whiteColor];
    _bigWightView.layer.masksToBounds=YES;
    _bigWightView.layer.cornerRadius=10.00*WEIGHT;
    [self.view addSubview:_bigWightView];
    [_bigWightView mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.top.equalTo(self.view).offset(66.00/2*HEIGHT);
        make.left.equalTo(self.view).offset(60.00 *WEIGHT/2);
        make.right.equalTo(self.view).offset(-60/2 *WEIGHT);
        make.height.mas_equalTo(420/2 *HEIGHT);
        
    }];
    
   
    //绿色框
    _imageView=[[UIImageView alloc]init];
    _imageView.image=[UIImage imageNamed:@"kuang"];
    _imageView.backgroundColor=[UIColor whiteColor];
    _imageView.userInteractionEnabled=YES;
    UITapGestureRecognizer *imageAction=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapActipn:)];
    [_imageView addGestureRecognizer:imageAction];
    [_bigWightView addSubview:_imageView];
    [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(_bigWightView).offset(65/2 *HEIGHT);
        make.left.equalTo(_bigWightView).offset(88/2 *WEIGHT);
        make.size.mas_equalTo(CGSizeMake(348/2 *WEIGHT, 231/2 *HEIGHT));
    }];
    
    
    //认证图片
    _renimage=[[UIImageView alloc]init];
    _renimage.image=[UIImage imageNamed:@"zheng"];
    [_bigWightView addSubview:_renimage];
    [_renimage mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(_imageView.mas_top).offset(82/2 *HEIGHT);
        make.left.equalTo(_imageView.mas_left).offset(125/2 *WEIGHT);
        make.size.mas_equalTo(CGSizeMake(112/2*WEIGHT, 100/2 *HEIGHT));
    }];
    
   
    //点击上传名片
    UILabel *jilabel=[[UILabel alloc]init];
    jilabel.text=@"点击上传名片";
    jilabel.textColor=[UIColor blackColor];
    jilabel.alpha=0.5;
    jilabel.font=[UIFont  systemFontOfSize:16];
    [_bigWightView addSubview:jilabel];
    [jilabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(_renimage.mas_bottom).offset(100/2 *HEIGHT);
        make.left.equalTo(_bigWightView.mas_left).offset(195/2 *WEIGHT);
        make.size.mas_equalTo(CGSizeMake(100 *WEIGHT, 22 *HEIGHT));
    }];
    
    //文字
    UILabel *wenlabel=[[UILabel alloc]init];
    wenlabel.text=@"   请上传名片正面保证清晰可辨认\n     家范儿姓名与名字中一致\n     注册手机号应与名片中一致 \n    [暂不支非互联网行业的认证]";
    wenlabel.textColor=[UIColor blackColor];
    wenlabel.alpha=0.5;
    wenlabel.lineBreakMode=NSLineBreakByTruncatingTail;
    wenlabel.numberOfLines=0;
    wenlabel.textAlignment=NSTextAlignmentCenter;
    wenlabel.font=[UIFont systemFontOfSize:14];
    [self.view addSubview:wenlabel];
    [wenlabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(_bigWightView.mas_bottom).offset(50/2 *HEIGHT);
        make.left.equalTo(self.view).offset(130/2 *WEIGHT);
        make.size.mas_equalTo(CGSizeMake(180 *WEIGHT, 100*HEIGHT));
    }];
    
    //提交审核
    _jiaobtn=[UIButton buttonWithType:UIButtonTypeCustom];
    _jiaobtn.backgroundColor=GH;
    _jiaobtn.layer.masksToBounds=YES;
    _jiaobtn.layer.cornerRadius=5;
    _jiaobtn.titleLabel.font=[UIFont fontWithName:@"Arial" size:LOGINFONT *TEXTWEIGHT];
    [_jiaobtn setTitle:@"提交审核" forState:UIControlStateNormal];
    [_jiaobtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_jiaobtn addTarget:self action:@selector(jiaoAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_jiaobtn];
    [_jiaobtn mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.bottom.equalTo(self.view.mas_bottom).offset(-70.00 *HEIGHT);
        make.left.equalTo(self.view).offset(44/2*WEIGHT);
        make.right.equalTo(self.view.mas_right).offset(-44/2*WEIGHT);
        make.height.mas_equalTo(78/2 *AUTO_HEIGHT);
    }];
   
}


#pragma mark   上传照片
-(void)  createShang
{
    //白色底框
    self.tsView = [[UIView alloc]init];
    self.tsView.alpha = 0;
    self.tsView.backgroundColor =[UIColor whiteColor];
    [self.view addSubview:self.tsView];
    [self.tsView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(self.view.mas_bottom).offset(0);
        make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width, 319.00 *HEIGHT/2));
    }];
    
    
    //拍照的图片
    UIButton * paisheButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [paisheButton setImage:[UIImage imageNamed:@"pai"] forState:UIControlStateNormal];
    [paisheButton addTarget:self action:@selector(shexiangtou:) forControlEvents:UIControlEventTouchUpInside];
    paisheButton.backgroundColor = [UIColor whiteColor];
    [self.tsView addSubview:paisheButton];
    [paisheButton mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.top.equalTo(self.tsView.mas_top).offset(39.00 *HEIGHT/2);
        make.left.equalTo(self.view.mas_left).offset(91.00 *WEIGHT /2);
        make.size.mas_equalTo(CGSizeMake(95.00 *WEIGHT/2, 95.00 *HEIGHT/2));
    }];
    
    //拍摄照片
    UILabel *psLabel = [[UILabel alloc]init];
    psLabel.text = @"拍摄照片";
    psLabel.textAlignment = NSTextAlignmentCenter;
    psLabel.font = [UIFont fontWithName:ZIXING size:13.00*WEIGHT];
    psLabel.alpha = 0.7;
    [self.tsView addSubview:psLabel];
    [psLabel mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.top.equalTo(paisheButton.mas_bottom).offset(0);
        make.left.equalTo(self.view.mas_left).offset(75.00 *WEIGHT/2);
        make.size.mas_equalTo(CGSizeMake(65.00 *WEIGHT, 95.00 *HEIGHT/2));
    }];
    
    
    UIButton * xiangceButton = [UIButton buttonWithType:UIButtonTypeCustom];
    xiangceButton.backgroundColor = [UIColor whiteColor];
    [xiangceButton setImage:[UIImage imageNamed:@"ce"] forState:UIControlStateNormal];
    [xiangceButton addTarget:self action:@selector(psAction:) forControlEvents:UIControlEventTouchUpInside];
    xiangceButton.backgroundColor = [UIColor whiteColor];
    [self.tsView addSubview:xiangceButton];
    [xiangceButton mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.top.equalTo(self.tsView.mas_top).offset(39.00 *HEIGHT/2);
        make.left.equalTo(paisheButton.mas_right).offset(91.00 *WEIGHT /2);
        make.size.mas_equalTo(CGSizeMake(95.00 *WEIGHT/2, 95.00 *HEIGHT/2));
        
    }];
    
    
    UILabel *xcLabel = [[UILabel alloc]init];
    xcLabel.text = @"相册照片";
    xcLabel.textAlignment = NSTextAlignmentCenter;
    xcLabel.font = [UIFont fontWithName:ZIXING size:13.00*WEIGHT];
    xcLabel.alpha = 0.7;
    [self.tsView addSubview:xcLabel];
    [xcLabel mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.top.equalTo(xiangceButton.mas_bottom).offset(0);
        make.left.equalTo(psLabel.mas_right).offset(15.00 *WEIGHT);
        make.size.mas_equalTo(CGSizeMake(95.00 *WEIGHT, 95.00 *HEIGHT/2));
    }];
    
    UIButton * jieButton = [UIButton buttonWithType:UIButtonTypeCustom];
    jieButton.backgroundColor = [UIColor whiteColor];
    [jieButton setImage:[UIImage imageNamed:@"kuai"] forState:UIControlStateNormal];
    [jieButton addTarget:self action:@selector(kuaAction:) forControlEvents:UIControlEventTouchUpInside];
    jieButton.backgroundColor = [UIColor whiteColor];
    [self.tsView addSubview:jieButton];
    [jieButton mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.top.equalTo(self.tsView.mas_top).offset(39.00 *HEIGHT/2);
        make.left.equalTo(xiangceButton.mas_right).offset(91.00 *WEIGHT /2);
        make.size.mas_equalTo(CGSizeMake(95.00 *WEIGHT/2, 95.00 *HEIGHT/2));
        
    }];
    
    
    UILabel *jieLabel = [[UILabel alloc]init];
    jieLabel.text = @"快捷回复";
    jieLabel.textAlignment = NSTextAlignmentCenter;
    jieLabel.font = [UIFont fontWithName:ZIXING size:13.00*WEIGHT];
    jieLabel.alpha = 0.7;
    [self.tsView addSubview:jieLabel];
    [jieLabel mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.top.equalTo(xiangceButton.mas_bottom).offset(0);
        make.left.equalTo(xcLabel.mas_right).offset(15.00 *WEIGHT);
        make.size.mas_equalTo(CGSizeMake(55.00 *WEIGHT, 95.00 *HEIGHT/2));
    }];
    

    
    
    UILabel *line  = [[UILabel alloc]init];
    line.backgroundColor = HS;
    line.alpha = 0.3;
    [self.tsView  addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.top.equalTo(xcLabel.mas_bottom).offset(2 *HEIGHT/2);
        make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width, 1.00 *HEIGHT));
    }];
    
    
    
    
    UIButton *quixaoButton = [[UIButton alloc]init];
    [quixaoButton addTarget:self action:@selector(quxiaoAction:) forControlEvents:UIControlEventTouchUpInside];
    quixaoButton.titleLabel.font=[UIFont fontWithName:ZIXING size:17.00*WEIGHT];
    [quixaoButton setTitle:@"取 消" forState:UIControlStateNormal];
    [quixaoButton setTitleColor:ZITI forState:UIControlStateNormal];
    [self.tsView addSubview:quixaoButton];
    [quixaoButton mas_makeConstraints:^(MASConstraintMaker *make){
        
        make.top.equalTo(line.mas_bottom).offset(4/2*HEIGHT);
        make.left.equalTo(self.view.mas_left).offset(self.view.frame.size.width/2-40 *WEIGHT);
        make.size.mas_equalTo(CGSizeMake(80.00 *WEIGHT, 40.00 *HEIGHT));
    }];
    
    
    _backView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-216.00 *HEIGHT)];
    _backView.alpha=0;
    _backView.backgroundColor=[UIColor grayColor];
    _backView.userInteractionEnabled=YES;
    UITapGestureRecognizer *backtap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(backAction:)];
    [_backView addGestureRecognizer:backtap];
    [self.view addSubview:_backView];


}


//照相功能
-(void)tapActipn:(UITapGestureRecognizer *)tap {
    
    if (self.headImage ==nil) {
        self.isSelrct= !self.isSelrct;
        if (self.isSelrct) {
            
            [UIView animateWithDuration:0.004 animations:^{
                _tsView.alpha = 1;
                _backView.alpha=0.1;
                _tsView.frame = CGRectMake(0, self.view.frame.size.height-163.00*HEIGHT, self.view.frame.size.width, 163.00*HEIGHT);
                
                _tsView.hidden=YES;
            } completion:^(BOOL finished) {
                _tsView.alpha = 1.0;
                _backView.alpha=0.1;
                _tsView.frame = CGRectMake(0, self.view.frame.size.height-163.00*HEIGHT, self.view.frame.size.width, 163.00*HEIGHT);
                
                _tsView.hidden=NO;
                
            }];
        }
        self.isSelrct= !self.isSelrct;
        
    }else{
        
        [SJAvatarBrowser showImage:(UIImageView *) tap.view];
        
        [UIView animateWithDuration:0.618 animations:^{
            
            _tsView.frame = CGRectMake(0, [[UIScreen mainScreen]bounds].size.height, self.view.frame.size.width, 319.00*HEIGHT/2);
            
        } completion:^(BOOL finished) {
            
            _tsView.frame = CGRectMake(0, [[UIScreen mainScreen]bounds].size.height, self.view.frame.size.width,319.00*HEIGHT/2);
            
        }];
        
    }
    
}


- (void)shexiangtou:(UIButton *)button {
    
    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
    if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
        sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    }
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];//初始化
    picker.delegate = self;
    picker.allowsEditing = NO;//设置可编辑
    picker.sourceType = sourceType;
    [self presentViewController:picker animated:YES completion:nil];//进入照相界面
}

- (void)psAction:(UIButton *)btn {
    
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    imagePicker.delegate = self;
    imagePicker.allowsEditing = NO;
    [self presentViewController:imagePicker animated:YES completion:nil];
}

-(void) kuaAction:(UIButton *) btn
{
    NSLog(@"快捷回复快捷回复快捷回复快捷回复");
}

-(void) backAction:(UITapGestureRecognizer *) tap
{
    
    self.backView.alpha=0;
    [UIView animateWithDuration:0.618 animations:^{
        _tsView.frame = CGRectMake(0, [[UIScreen mainScreen]bounds].size.height, self.view.frame.size.width, 319.00*HEIGHT/2);
        
    } completion:^(BOOL finished) {
        _tsView.frame = CGRectMake(0, [[UIScreen mainScreen]bounds].size.height, self.view.frame.size.width,319.00*HEIGHT/2);
        
    }];
}

// 选中照片
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    
    self.headImage = [info objectForKey:UIImagePickerControllerOriginalImage];
    [picker dismissViewControllerAnimated:YES completion:NULL];
    [_imageView setImage:self.headImage];
    
    _renimage.alpha=0;
    self.backView.alpha=0;
    
    
    [UIView animateWithDuration:0.618 animations:^{
        _tsView.frame = CGRectMake(0, [[UIScreen mainScreen]bounds].size.height, self.view.frame.size.width, 319.00*HEIGHT/2);
        
    } completion:^(BOOL finished) {
        _tsView.frame = CGRectMake(0, [[UIScreen mainScreen]bounds].size.height, self.view.frame.size.width,319.00*HEIGHT/2);
        
    }];
    
}

//取消按钮
-(void)quxiaoAction:(UIButton*)button {
    
    _backView.alpha=0;
    [UIView animateWithDuration:0.618 animations:^{
        _tsView.frame = CGRectMake(0, [[UIScreen mainScreen]bounds].size.height, self.view.frame.size.width, 319.00*HEIGHT/2);
        
    } completion:^(BOOL finished) {
        _tsView.frame = CGRectMake(0, [[UIScreen mainScreen]bounds].size.height, self.view.frame.size.width,319.00*HEIGHT/2);
        
    }];
}


//返回按钮
-(void) Back:(UIButton *) btn
{
    [self.navigationController popViewControllerAnimated:YES];
}

//提交审核
-(void) jiaoAction:(UIButton *) btn
{
    NSLog(@"提交审核提交审核提交审核");
}

@end
